package com.cn.bio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.channels.SocketChannel;

public class BioDemo {

  public static void main(String[] args) {
//    SocketChannel

    //bind
    try {
      ServerSocket serverSocket = new ServerSocket();
      serverSocket.bind(new InetSocketAddress(8080));
      while (true) {
        Socket accept = serverSocket.accept();
        SocketChannel channel = accept.getChannel();
        System.out.println(accept + "=>" + channel);

        try {
          InputStream inputStream = accept.getInputStream();
          BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
          bufferedReader.lines().forEach(line -> System.out.println(line));
        } catch (IOException e) {
          e.printStackTrace();
        }

      }

      //      serverSocket.listen();
    } catch (IOException e) {
      e.printStackTrace();
    }

  }


}
